
<!DOCTYPE html>
<html>
  <head>
    <title>toPairs</title>
    <link rel="stylesheet" href="prism.css">
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div id="header">
      <div class="doc-title"><a href="folktale.html"><span class="doc-title"><span class="product-name">Folktale</span><span class="version">v2.1.0</span></span></a><ul class="navigation"><li class="navigation-item"><a href="https://github.com/origamitower/folktale" title="">GitHub</a></li><li class="navigation-item"><a href="/docs/support/" title="">Support</a></li><li class="navigation-item"><a href="/docs/v2.1.0/contributing/" title="">Contributing</a></li></ul></div>
    </div>
    <div id="content-wrapper"><div id="content-panel"><h1 class="entity-title">toPairs</h1><div class="highlight-summary"><div><p>Returns pairs of <code>(key, value)</code> for all own enumerable properties in an object.</p>
</div></div><div class="definition"><h2 class="section-title" id="signature">Signature</h2><div class="signature">toPairs(object)</div><div class="type-definition"><div class="type-definition-container"><div class="type-title-container"><strong class="type-title">Type</strong><a class="info" href="/docs/v2.1.0/misc/type-notation/">(what is this?)</a></div><pre class="type"><code class="language-haskell">(Object 'a) =&gt; Array (String or Symbol, 'a)</code></pre></div></div></div><h2 class="section-title">Documentation</h2><div class="documentation"><div><p>Returns pairs of <code>(key, value)</code> for all own enumerable properties in an object.</p>
<h2 id="example-">Example:</h2>
<pre><code>const toPairs = require(&#39;folktale/core/object/to-pairs&#39;);

const pair = { x: 10, y: 20 };
toPairs(pair);
// ==&gt; [[&#39;x&#39;, 10], [&#39;y&#39;, 20]]
// (in ES5- VMs this may be [[&#39;y&#39;, 20], [&#39;x&#39;, 10]])
</code></pre><h2 id="why-">Why?</h2>
<p>Objects in JavaScript are commonly used as dictionaries, but natively
there are no operations to work with them in that way. This function
allows one to extract the <code>(key, value)</code> pairs from an object:</p>
<pre><code>const toPairs = require(&#39;folktale/core/object/to-pairs&#39;);

const pair = { x: 10, y: 20 };
toPairs(pair);
// ==&gt; [[&#39;x&#39;, 10], [&#39;y&#39;, 20]]
// or  [[&#39;y&#39;, 20], [&#39;x&#39;, 10]]
</code></pre><p>Inherited properties, and those that are not marked as enumerable, are
not returned in the resulting array:</p>
<pre><code>const p1 = { z: 2 };
const pair2 = Object.create(p1);
pair2.x = 10; pair2.y = 20;

toPairs(pair2);
// ==&gt; [[&#39;x&#39;, 10], [&#39;y&#39;, 20]]
// or  [[&#39;y&#39;, 20], [&#39;x&#39;, 10]]

// non-enumerable property x
Object.defineProperty(p1, &#39;x&#39;, { value: 1 });

toPairs(p1);
// ==&gt; [[&#39;z&#39;, 2]]
</code></pre><h2 id="caveats">Caveats</h2>
<p>While ECMAScript 2015 specifies that objects are ordered using
insertion order, you&#39;re not guaranteed to get that behaviour in
any non-ES2015 engine, so for all effects it&#39;s better to treat
the result of this operation as an unordered collection.</p>
</div></div><div class="members"><h2 class="section-title" id="properties">Properties</h2></div><div class="source-code"><h2 class="section-title" id="source-code">Source Code</h2><div class="source-location">Defined in source/core/object/to-pairs.js at line 20, column 0</div><pre class="source-code"><code class="language-javascript">(object) =&gt; Object.keys(object).map(k =&gt; [k, object[k]])</code></pre></div></div><div id="meta-panel"><div class="meta-section"><div class="meta-field"><strong class="meta-field-title">Stability</strong><div class="meta-field-value">stable</div></div><div class="meta-field"><strong class="meta-field-title">Licence</strong><div class="meta-field-value">MIT</div></div><div class="meta-field"><strong class="meta-field-title">Module</strong><div class="meta-field-value">folktale/core/object/to-pairs</div></div></div><div class="table-of-contents"><div class="meta-section-title">On This Page</div><ul class="toc-list level-1"><li class="toc-item"><a href="#signature">Signature</a></li><li class="toc-item"><span class="no-anchor">Documentation</span><ul class="toc-list level-2"><li class="toc-item"><a href="#example-" title="Example:"><div><p>Example:</p>
</div></a></li><li class="toc-item"><a href="#why-" title="Why?"><div><p>Why?</p>
</div></a></li><li class="toc-item"><a href="#caveats" title="Caveats"><div><p>Caveats</p>
</div></a></li></ul></li><li class="toc-item"><a href="#properties">Properties</a><ul class="toc-list level-2"></ul></li><li class="toc-item"><a href="#source-code">Source Code</a></li></ul></div><div class="meta-section"><strong class="meta-section-title">Authors</strong><div class="meta-field"><strong class="meta-field-title">Copyright</strong><div class="meta-field-value">(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS</div></div><div class="meta-field"><strong class="meta-field-title">Authors</strong><div class="meta-field-value"><ul class="meta-list"><li>Quildreen Motta</li></ul></div></div><div class="meta-field"><strong class="meta-field-title">Maintainers</strong><div class="meta-field-value"><ul class="meta-list"><li>Quildreen Motta &lt;queen@robotlolita.me&gt; (http://robotlolita.me/)</li></ul></div></div></div></div></div>
    <script>
void function() {
  var xs = document.querySelectorAll('.documentation pre code');
  for (var i = 0; i < xs.length; ++i) {
    xs[i].className = 'language-javascript code-block';
  }
}()
    </script>
    <script src="prism.js"></script>
  </body>
</html>